<!DOCTYPE html>
<html lang="en">
<head>
    <include file="Public:head"/>
</head>
<body>
    <div class="container-fluid">
        <div class="form">
            <div class="form-group">
                <label>原密码：</label>
                <input class="form-control" name="old-pwd" placeholder="请输入原密码"/>
            </div>
            <div class="form-group">
                <label>新密码：</label>
                <input class="form-control" name="new-pwd" placeholder="请输入新密码"/>
            </div>
            <div class="form-group">
                <label>密码确认：</label>
                <input class="form-control" name="new-pwd-sure" placeholder="请再次输入新密码"/>
            </div>
            <div class="form-group">
                <button id="btn-sure" class="btn btn-primary">确认修改</button>
            </div>
        </div>
    </div>
</body>
<div id="myModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">消息提示</h4>
        </div>
        <div class="modal-body">
            <p id="err-msg"></p>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">确认</button>
        </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
    $("#btn-sure").click(function(){
        if(!checkParam()){
            return;
        }
        var old_pwd = $("#input[name='old_pwd']").val().trim();
        var new_pwd = $("input[name='new-pwd']").val().trim();
        $.ajax({
            url: "__URL__/ajax_change_pwd",
            data:{new_pwd:new_pwd, old_pwd:old_pwd},
            dataType:"json",
            type:"post",
            success:function(data){
                if(data.code !=1){
                    alertMsg({"msg":data.msg, "type":0});
                }else{
                    alertMsg({"msg":data.msg});
                }
            }
        });
    });

    function checkParam(){
        var old_pwd = $("#input[name='old_pwd']").val().trim();
        var new_pwd = $("input[name='new-pwd']").val().trim();
        var new_pwd_sure = $("input[name='new-pwd-sure']").val().trim();

        if(old_pwd==""){
            $("#err-msg").text("请输入原密码！");
            $("#myModal").modal();
            return false;
        }
        if(new_pwd==""){
            $("#err-msg").text("请输入新密码！");
            $("#myModal").modal();
            return false;
        }
        if(new_pwd_sure==""){
            $("#err-msg").text("请输入密码确认！");
            $("#myModal").modal();
            return false;
        }
        if(new_pwd!=new_pwd_sure){
            $("#err-msg").text("两次输入的密码不相同！");
            $("#myModal").modal();
            return false;
        }
        if(new_pwd.length<8){
            $("#err-msg").text("密码长度必须大于等于8");
            $("#myModal").modal();
            return false;
        }
        return true;
    }
</script>